
;define(function(){
	CafeJS.playTool = function(options){
		var defaultOptions = {
			"tplUrl" : CafeJS.CXT + "static/widgets/cafejs/script/playTool/playTool.html",
			"imgUrl" : CafeJS.CXT + "static/widgets/cafejs/themes/default/playTool/img/",
			"container" : null,					//容器 对象
			"callback" : null,					//回调函数(关闭窗口回调)
			"numSize" : 6,						//分割个数
			"time" : "2017-08-16 12:00:00",		//时间（结束时间）
			"gisId" : '',						//GIS地图ID
			"proId" : "",						//产品
			"key" : "",							//配色
			"layerInfo" : null,					//图层信息
			"layerIds" : [],
			"queryType" : null,					//queryType --- ("zdzG"--自动站,"ldzw"--雷达组网,"dzld"--单站) 或者 function
			"statcd" : "",						//站号
			"eno" : "",							//仰角
			"initCallBack" : null,				//加载完成后回调
		};
		
		var player = {
			_init : function(){
				$.extend(defaultOptions,options);
				if(defaultOptions.proId == "HJ"){
					defaultOptions.tplUrl =  CafeJS.CXT + "static/widgets/cafejs/script/playTool/playTool2.html";
					if(defaultOptions.container){
						var $wrap = this.getTpl();
						this.initLayer($wrap);
//						this.queryInfo($wrap)
						this.bindEventHJ($wrap);
                        this.recoverLayer2($wrap);
					}
				}else{
					if(defaultOptions.container){
						var $wrap = this.getTpl();
						this.initLayer($wrap);
						this.queryInfo($wrap)
						this.bindEvent($wrap);
					}
				}
			},
			getTpl : function(){						//获取图例模板
				var html;
				$.ajax({
					type : "GET",
					url : defaultOptions.tplUrl,
					dataType : "html",
					async : false,
					success : function(res){
						html = res;
					}
				});
				return $(html);
			},
			initLayer : function($wrap){				//初始化布局
				defaultOptions.container.show();
				defaultOptions.container.append($wrap);
				var width =$wrap.find(".cafe-tl-sta-t-defbg").width();
				var spanWidth = $wrap.find(".cafe-tl-sta-timelabel>span").width();
				
				if(	defaultOptions.proId == "HJ"){
					var marginRight = width/(defaultOptions.numSize) - spanWidth;
				}else{
					var marginRight = width/defaultOptions.numSize - spanWidth;
				}
				$wrap.find(".cafe-tl-sta-timelabel>span").css({"margin-right" : marginRight+'px'});
				$wrap.find(".cafe-tl-sta-timelabel>span").last().css({"margin-right" : '0px'});
				this.initTime($wrap);
			},
			recoverLayer : function($wrap){				//恢复初始化布局
				if($wrap.find(".cafe-tl-play-icon").hasClass("active")){
					clearInterval($(".cafe-tl-play-icon").val());
					$wrap.find(".cafe-tl-play-icon").removeClass("active");
				}
				var width = $wrap.find(".cafe-tl-sta-timearea").width();
				$wrap.find(".cafe-tl-sta-t-slider").css({'left':width-12+'px'});
				$wrap.find(".cafe-tl-sta-t-tip").css({'left':width-12-60+'px'});
				$wrap.find(".cafe-tl-sta-t-bg").css({'width':width+'px'});
				var showTime = $wrap.find(".cafe-tl-sta-timelabel>span").last().text();
				$wrap.find(".cafe-tl-sta-t-tip>span").text(showTime);
				GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
			},
			recoverLayer2 : function($wrap){				//恢复初始化布局
				if($wrap.find(".cafe-tl-play-icon").hasClass("active")){
					clearInterval($(".cafe-tl-play-icon").val());
					$wrap.find(".cafe-tl-play-icon").removeClass("active");
				}
				var width = 0;
				$wrap.find(".cafe-tl-sta-t-slider").css({'left':width-12+'px'});
				$wrap.find(".cafe-tl-sta-t-tip").css({'left':width-12-60+'px'});
				$wrap.find(".cafe-tl-sta-t-bg").css({'width':width+'px'});
				var showTime = $wrap.find(".cafe-tl-sta-timelabel>span").first().text();
				$wrap.find(".cafe-tl-sta-t-tip>span").text(showTime);
			},
			//根据时间修改播放条时间刻度
			initTime : function($wrap){
				if(defaultOptions.proId == "HJ"){		//环境
                    var selectHour = $wrap.find(".cafe-tl-d-container span.active").attr("sid");
                    $wrap.find(".cafe-tl-sts-tl-name").attr("tmid",selectHour);
                    $wrap.find(".cafe-tl-sts-tl-name").text(4+"小时");
					//计算时间
					var startTime = defaultOptions.time;
						startTime = Date.parse(startTime.replace(/-/g,"/"));
					var jgSJ = Number(selectHour) * 60 * 60 * 1000 / defaultOptions.numSize;
					for(var i=0;i<=defaultOptions.numSize;i++){
						var eachSpan = $wrap.find(".cafe-tl-sta-timelabel>span").eq(i);
						var eachTime = startTime + i*jgSJ;
						eachTime = new Date(eachTime).format("yyyy-MM-dd hh:mm");
						eachSpan.attr("time",eachTime);
						eachSpan.text(eachTime.substring(11,16));
					}
				}else{
                    var selectHour = $wrap.find(".cafe-tl-d-container span.active").attr("sid");
						$wrap.find(".cafe-tl-sts-tl-name").attr("tmid",selectHour);
						$wrap.find(".cafe-tl-sts-tl-name").text(selectHour+"小时");
					//计算时间	
					var endTime = defaultOptions.time;
					var startTime = Date.parse(endTime.replace(/-/g,"/")) - Number(selectHour) * 60 * 60 * 1000;
					var jgSJ = Number(selectHour) * 60 * 60 * 1000 / defaultOptions.numSize;
					for(var i=0;i<=defaultOptions.numSize;i++){
						var eachSpan = $wrap.find(".cafe-tl-sta-timelabel>span").eq(i);
						var eachTime = startTime + i*jgSJ;
						eachTime = new Date(eachTime).format("yyyy-MM-dd hh:mm");
						eachSpan.attr("time",eachTime);
						eachSpan.text(eachTime.substring(11,16));
					}
				}
			},
			//获取播放数据时间数组
			getPlayDataTimeArr : function($wrap){
				var curtime = new Date(defaultOptions.time);
				var mintime = new Date(defaultOptions.time);
				var duration = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
					mintime.setMinutes(mintime.getMinutes() - duration);
				var dtimeInterval = this.getSmoothti(duration)[1];
				var timeArr = [];
				while (curtime.getTime() >= mintime.getTime()) {
					timeArr.push(mintime.format("yyyyMMddhhmmss"));
					mintime.setMinutes(mintime.getMinutes() + dtimeInterval);
				}
				return timeArr;
			},
			//平滑时间轴上时间刻度间隔和数据时间间隔
			getSmoothti : function(t){
				if(defaultOptions.queryType == 'zdzG'){
					switch (t) {
						case 3*60:
							return [30,5];
						case 6*60:
							return [60,30];
					}
				}else if(defaultOptions.queryType == 'ldzw'){
					switch (t) {
						case 3*60:
							return [30,12];
						case 6*60:
							return [60,30];
					}
				}else if(defaultOptions.queryType == 'dzld'){
					switch (t) {
						case 3*60:
							return [30,12];
						case 6*60:
							return [60,30];
					}
				}else if(defaultOptions.queryType == 'sdmd'){
					switch (t) {
						case 3*60:
							return [30,10];
						case 6*60:
							return [60,30];
					}
				}else{
					switch (t) {
						case 3*60:
							return [30,5];
						case 6*60:
							return [60,30];
					}
				}
			},
			/**
			 * 播放
			 */
			play : function($wrap,defaultOptions){
				clearInterval($wrap.find(".cafe-tl-play-icon").val());
				var interval = -1;
				var ti = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
				var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
				var per = ti / bgW;
				var frameNumber = 60;
				var step = (parseFloat($wrap.find(".cafe-tl-sta-timelabel>span:eq(1)").css("margin-left")) + 32) / frameNumber;
				var avgss = 1000/frameNumber;
				interval = setInterval(function(){
					var $tip = $wrap.find(".cafe-tl-sta-t-tip");
					var $slider = $wrap.find(".cafe-tl-sta-t-slider");
					var sliderleft = parseFloat($slider.css("left")) + step;
					if(sliderleft >= bgW - 12){
						sliderleft = -12;
					}
					$slider.css("left", sliderleft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(sliderleft + 12) + "px");
					var time = new Date($wrap.find(".cafe-tl-sta-timelabel").find("span:first").attr("time"));
					time.setMinutes(time.getMinutes() + Math.round((sliderleft + 12) * per));
					$tip.css("left",(sliderleft - 60) + "px").find("span").text(time.format("hh:mm"));
	
					var playData = $wrap.find(".cafe-tl-smooth").data("playData");
					$.each(playData,function(k,pd){
						if(!$.isEmptyObject(pd)){
							GIS.GridShow.animate(defaultOptions.gisId,pd.layerIds,pd.timesArr,time.getTime());
						}
					});
				}, avgss);
				
				$wrap.find(".cafe-tl-play-icon").val(interval);
			},
			/**
			 * 播放 (环境)
			 */
			play2 : function($wrap,defaultOptions){
				clearInterval($wrap.find(".cafe-tl-play-icon").val());
				var interval = -1;
				var ti = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
				var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
				var per = ti / bgW;
				var frameNumber = 60;
				var step = (parseFloat($wrap.find(".cafe-tl-sta-timelabel>span:eq(1)").css("margin-left")) + 32) / frameNumber;
				var avgss = 1000/frameNumber;
				interval = setInterval(function(){
					var $tip = $wrap.find(".cafe-tl-sta-t-tip");
					var $slider = $wrap.find(".cafe-tl-sta-t-slider");
					var sliderleft = parseFloat($slider.css("left")) + step;
					if(sliderleft >= bgW - 12){
						sliderleft = -12;
					}
					$slider.css("left", sliderleft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(sliderleft + 12) + "px");
					var time = new Date($wrap.find(".cafe-tl-sta-timelabel").find("span:first").attr("time"));
					time.setMinutes(time.getMinutes() + Math.round((sliderleft + 12) * per));
					$tip.css("left",(sliderleft - 60) + "px").find("span").text(time.format("hh:mm"));
				
					
					GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,defaultOptions.times,time.getTime());
				}, avgss);
				
				$wrap.find(".cafe-tl-play-icon").val(interval);
			},
			//查询数据
			queryInfo : function($wrap){
				if(defaultOptions.queryType == "zdzG"){
					this.queryZdz($wrap);
				}else if(defaultOptions.queryType == "ldzw"){
					this.queryZw($wrap);
				}else if(defaultOptions.queryType == "dzld"){
					this.queryDzld($wrap);
				}else if(defaultOptions.queryType == "sdmd"){
					this.queryLighDensity($wrap);
				}else{
					if($.isFunction(defaultOptions.queryType)){
						
					}
				}	
			},
			//闪电密度
			queryLighDensity : function($wrap){
				var times = this.getPlayDataTimeArr($wrap);
				var	time = times.toString(); 
				var key = defaultOptions.key;
				var proId = defaultOptions.proId;
				var layerInfo = defaultOptions.layerInfo;
				
				var playData = {};
				var layerIds = defaultOptions.layerIds;
				var timesArr = [];
				for(var j=0;j<times.length;j++){
					var rachTime = times[j];
					if(rachTime.length == 14){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":" + rachTime.substring(12,14);
					}else if(rachTime.length == 12){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":00";
					}
					rachTime = new Date(rachTime).getTime();
					timesArr.push(rachTime);
				}
				playData[proId]	= {layerIds : layerIds,timesArr : timesArr}
				$wrap.find(".cafe-tl-smooth").data("playData",playData);
				
				var xhr = new XMLHttpRequest();
				var parameters = "&time="+time+"&ptype="+proId;
					xhr.open('post',CafeJS.CXT + "yjxhData/getLighDensity.do",true);
					xhr.responseType='arraybuffer';
					xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					xhr.onload=function(e){
						var info = this.response;
						if(info && info.byteLength>0){
							//删除图层
							GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
							var colorObj = {};
							if(CafeJS.DL_MAIN.legendsColor[key]){
								colorObj = CafeJS.DL_MAIN.legendsColor[key];
							}
							GIS.GridShow.showByTypes_raw(CafeJS.DL_MAIN.dlGisId,layerInfo,this.response,{},colorObj,null,null);
							//获取数据返回时间
							var returnTimesArr = player.parseTimes(info);
							$wrap.find(".cafe-tl-smooth").data("playData",{proId : {layerIds : layerIds,timesArr : returnTimesArr}});
							//展示最后一个时间点数据
							var lastTime = returnTimesArr[returnTimesArr.length-1];
							GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,returnTimesArr,lastTime);
							//
							if($.isFunction(defaultOptions.initCallBack)){
								defaultOptions.initCallBack();
							}
						}
					}
				xhr.send(parameters);
			},
			//单站雷达数据  queryTime--不传（为点击雷达要素查询）  queryTime--传值（为图例左右切换查询）
			queryDzld : function($wrap){
				var times = this.getPlayDataTimeArr($wrap);
				var	time = times.toString(); 
				var key = defaultOptions.key;
				var proId = defaultOptions.proId;
				var layerInfo = defaultOptions.layerInfo;
				
				var statcd = defaultOptions.statcd;
				var eno = defaultOptions.eno;
		
				var playData = {};
				var layerIds = defaultOptions.layerIds;
				var timesArr = [];
				for(var j=0;j<times.length;j++){
					var rachTime = times[j];
					if(rachTime.length == 14){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":" + rachTime.substring(12,14);
					}else if(rachTime.length == 12){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":00";
					}
					rachTime = new Date(rachTime).getTime();
					timesArr.push(rachTime);
				}
				playData[proId]	= {layerIds : layerIds,timesArr : timesArr}
				$wrap.find(".cafe-tl-smooth").data("playData",playData);

				var xhr = new XMLHttpRequest();
				var parameters = "&statcd="+statcd+"&time="+time+"&pcode="+proId+"&eno="+eno+"";
					xhr.open('post',CafeJS.CXT + "yjxhData/getGridDataAsByte.do",true);
					xhr.responseType='arraybuffer';
					xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					xhr.onload=function(e){
						var info = this.response;
						if(info && info.byteLength>0){
							//删除图层
							GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
							var colorObj = {};
							if(CafeJS.DL_MAIN.legendsColor[key]){
								colorObj = CafeJS.DL_MAIN.legendsColor[key];
							}
							GIS.GridShow.showByTypes_raw(CafeJS.DL_MAIN.dlGisId,layerInfo,this.response,{},colorObj,null,null);
							//获取数据返回时间
							var returnTimesArr = player.parseTimes(info);
							$wrap.find(".cafe-tl-smooth").data("playData",{proId : {layerIds : layerIds,timesArr : returnTimesArr}});
							//展示最后一个时间点数据
							var lastTime = returnTimesArr[returnTimesArr.length-1];
							GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,returnTimesArr,lastTime);
							//
							if($.isFunction(defaultOptions.initCallBack)){
								defaultOptions.initCallBack();
							}
						}			
					}
				xhr.send(parameters);
			},
			//雷达组网
			queryZw : function($wrap){
				var times = this.getPlayDataTimeArr($wrap);
				var	time = times.toString(); 
				var key = defaultOptions.key;
				var proId = defaultOptions.proId;
				var layerInfo = defaultOptions.layerInfo;
		
				var playData = {};
				var layerIds = defaultOptions.layerIds;
				var timesArr = [];
				for(var j=0;j<times.length;j++){
					var rachTime = times[j];
					if(rachTime.length == 14){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":" + rachTime.substring(12,14);
					}else if(rachTime.length == 12){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":00";
					}
					rachTime = new Date(rachTime).getTime();
					timesArr.push(rachTime);
				}
				playData[proId]	= {layerIds : layerIds,timesArr : timesArr}
				$wrap.find(".cafe-tl-smooth").data("playData",playData);
			
				var xhr = new XMLHttpRequest();
				var parameters = "&time="+time+"&ptype="+proId+"";
				xhr.open('post',CafeJS.CXT + "yjxhData/getGridDataZW.do",true);
				xhr.responseType='arraybuffer';
				xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				xhr.onload=function(e){
					var info = this.response;
					if(info && info.byteLength>0){
						//删除图层
						GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
						GIS.GridShow.showByTypes_raw(CafeJS.DL_MAIN.dlGisId,layerInfo,this.response,{},CafeJS.DL_MAIN.legendsColor[key],null,null);
						//获取数据返回时间
						var returnTimesArr = player.parseTimes(info);
						$wrap.find(".cafe-tl-smooth").data("playData",{proId : {layerIds : layerIds,timesArr : returnTimesArr}});
						//展示最后一个时间点数据
						var lastTime = returnTimesArr[returnTimesArr.length-1];
						GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,returnTimesArr,lastTime);
						//
						if($.isFunction(defaultOptions.initCallBack)){
							defaultOptions.initCallBack();
						}
					}
				}
				xhr.send(parameters);
			},
			//自动站格点
			queryZdz : function($wrap){
				var times = this.getPlayDataTimeArr($wrap);
				var	time = times.toString(); 
				var key = defaultOptions.key;
				var proId = defaultOptions.proId;
				var layerInfo = defaultOptions.layerInfo;
				
				var playData = {};
				var layerIds = defaultOptions.layerIds;
				var timesArr = [];
				for(var j=0;j<times.length;j++){
					var rachTime = times[j];
					if(rachTime.length == 14){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":" + rachTime.substring(12,14);
					}else if(rachTime.length == 12){
						rachTime = rachTime.substring(0,4) + "-" + rachTime.substring(4,6) + "-" + rachTime.substring(6,8) + " " + rachTime.substring(8,10) + ":" + rachTime.substring(10,12) + ":00";
					}
					rachTime = new Date(rachTime).getTime();
					timesArr.push(rachTime);
				}
				playData[proId]	= {layerIds : layerIds,timesArr : timesArr}
				$wrap.find(".cafe-tl-smooth").data("playData",playData);

				var xhr = new XMLHttpRequest();
				var parameters = "&time="+time+"&proId="+proId;
					xhr.open('post',CafeJS.CXT + "yjxhData/getAutoStationAsByte.do",true);
					xhr.responseType='arraybuffer';
					xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					xhr.onload=function(e){
						var info = this.response;
						if(info && info.byteLength>0){
							//删除图层
							GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
							var colorObj = {};
							if(CafeJS.DL_MAIN.legendsColor[key]){
								colorObj = CafeJS.DL_MAIN.legendsColor[key];
							}
							colorObj.cutFlag=true;
							colorObj.areaCode=user.codeId;
							colorObj.smooth=false;
							GIS.GridShow.showByTypes_raw(CafeJS.DL_MAIN.dlGisId,layerInfo,this.response,{},colorObj,null,null);
							//获取数据返回时间
							var returnTimesArr = player.parseTimes(info);
							$wrap.find(".cafe-tl-smooth").data("playData",{proId : {layerIds : layerIds,timesArr : returnTimesArr}});
							//展示最后一个时间点数据
							var lastTime = returnTimesArr[returnTimesArr.length-1];
							GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,returnTimesArr,lastTime);
							//
							if($.isFunction(defaultOptions.initCallBack)){
								defaultOptions.initCallBack();
							}
						}
					}
				xhr.send(parameters);
			},
			//获取数据返回时间
			parseTimes : function(data){
				var d_view = new DataView(data)
				var aCols = d_view.getUint16(15);
				var aRows = d_view.getUint16(17);
				var timesArr=[],offset=43;
				for(var i=0,len = aCols*aRows;i<len;i++){
					timesArr.push(d_view.getUint32(offset+i*8)*Math.pow(2,32)+d_view.getUint32(offset+i*8+4));
				}
				return timesArr;
			},
			//关闭窗口
			closeWin : function(){
				defaultOptions.container.find(".cafe-tl-close-icon").trigger("click");
			},
			bindEvent : function($wrap){
				var that = this;
				
				//显示隐藏 时间选择项
				$wrap.find(".cafe-tl-sts-tselect").click(function(){
					if($(this).hasClass("active")){
						$(this).removeClass("active");
						$(this).parents(".cafe-tl-smooth").siblings(".cafe-tl-d-container").hide();
					}else{
						$(this).addClass("active");
						$(this).parents(".cafe-tl-smooth").siblings(".cafe-tl-d-container").show();
					}
				})
				
				// 时间选择项点击事件
				$wrap.find(".cafe-tl-d-container .cafe-tl-d-line span").unbind("click").bind("click",function(){
					if(!$(this).hasClass("active")){
						$(this).parents(".cafe-tl-d-container").find(".active").removeClass("active");
						$(this).addClass("active");
						that.initTime($wrap);
						that.recoverLayer($wrap);
						that.queryInfo($wrap);
					}
				})
				
			//单击弹出框的头部，确定点击处的位置
			$wrap.find(".cafe-tl-smooth").mousedown(function(event){
				var select = $wrap.find(".cafe-tl-sts-tselect");
				var slider = $wrap.find(".cafe-tl-sta-t-slider");
				var left = $wrap.find(".cafe-tl-left-icon");
				var player = $wrap.find(".cafe-tl-play-icon");
				var right = $wrap.find(".cafe-tl-right-icon");
				var close = $wrap.find(".cafe-tl-close-icon");
				
				if(!select.is(event.target) && !slider.is(event.target) && !left.is(event.target) && !player.is(event.target) && !right.is(event.target) && !close.is(event.target)){
					$(this).css({"cursor": "all-scroll"});						//点击鼠标切换图形
					event.stopPropagation();
					event.preventDefault();
					var isMove = true;
					var _this = defaultOptions.container;
			
					var m_x = Number(_this.css("left").split("px")[0]);//点击窗体时，left
					var m_y = Number(_this.css("top").split("px")[0]);//点击窗体时，top
					var abs_x = event.pageX;		//点击窗体时，左边距
					var abs_y = event.pageY;		//点击窗体时，上边距
					//单击住头部可进行拖拽，计算移动大小，以及移动范围限制
					$(document).unbind('mousemove').bind('mousemove',function(event){
						if(isMove) {
							//event.pageX,移动后的左边距;event.pageY,移动后的上边距
							var ebs_x = m_x-(abs_x-event.pageX); //移动后的left
							var ebs_y = m_y+(event.pageY - abs_y);//移动后的top
							
							var body_w =  $('.cafe-container').width();
							var body_h = $('.cafe-container').height();
							
							var div_w = _this.find(".cafe-tl-smooth").outerWidth();
							var div_h = _this.find(".cafe-tl-smooth").outerHeight();
							//不可超出左右边框
							if(ebs_x <= 0) {
								ebs_x = 0;
							} else if (ebs_x > body_w - div_w) {
								ebs_x = body_w - div_w;
							} 
							
							//不可超出上下边框
							if(ebs_y <= 0) {
								ebs_y = 0;
							} else if (ebs_y > body_h - div_h) {	//减去上下的蓝边高
								ebs_y = body_h - div_h;
							} 
							
							//重新设定弹出框的左边距，上边距
							_this.css({'left':ebs_x,'top':ebs_y });
						}
					}).mouseup(function(){
						isMove = false
						$(document).unbind('mousemove');
					});//鼠标移除事件；单击事件结束事件。
				}
			});
				
				
				$wrap.off().on("mousedown",".cafe-tl-sta-t-slider",function(event){	//拖动滑块
					var left = parseFloat($(this).css("left"));
					var that = this;
					var ti = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
					var bgW =  $(this).siblings(".cafe-tl-sta-t-defbg").width();
					var per = ti / bgW;
					window.document.onmousemove = function(ev){
						ev.preventDefault();
						var step = 1;
						var $tip = $(that).siblings(".cafe-tl-sta-t-tip");
						var offset = ev.pageX-event.pageX;
						var _left = left + Math.round(offset / step) * step;
						if(_left <= -12){
							_left = -12;
						}else if(_left >= bgW - 12){
							_left = bgW - 12;
						}
						$(that).css("left",_left + "px").siblings(".cafe-tl-sta-t-bg").css("width",(_left + 12) + "px");
						var time = new Date($wrap.find(".cafe-tl-sta-timelabel").find("span:first").attr("time"));
						time.setMinutes(time.getMinutes() + Math.round((_left + 12) * per));
						$tip.css("left",(_left - 60) + "px").find("span").text(time.format("hh:mm"));
						
						var playData = $(that).closest(".cafe-tl-smooth").data("playData");
						$.each(playData,function(k,pd){
							if(!$.isEmptyObject(pd)){
								GIS.GridShow.animate(defaultOptions.gisId,pd.layerIds,pd.timesArr,time.getTime());
							}
						});
					};
					window.document.onmouseup = function(){
						window.document.onmousemove = null;
						window.document.onmouseup = null;
					};
				}).on("click",".cafe-tl-left-icon",function(){						//点击向左
						var $slider = $(".cafe-tl-sta-t-slider");
						var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
						var $tip = $wrap.find(".cafe-tl-sta-t-tip");
						var timeArr = that.getPlayDataTimeArr($wrap);
						var duration = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
						var timeInterval = that.getSmoothti(duration)[1];
						var step = bgW / (duration / timeInterval);
						var curLeft = parseFloat($slider.css("left")) - step;
						var index = Math.ceil(curLeft/step);
						if(curLeft <= -12){
							index = 0;
							curLeft = -12;
						}
						$slider.css("left",curLeft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(curLeft + 12) + "px");
						var time = new Date(dateUtil.convertStringToDate7(timeArr[index],"yyyy-MM-dd hh:mm:ss"));
						$tip.css("left",(curLeft - 60) + "px").find("span").text(time.format("hh:mm"));
					
						var playData = $wrap.find(".cafe-tl-smooth").data("playData");
						$.each(playData,function(k,pd){
							if(!$.isEmptyObject(pd)){
								GIS.GridShow.animate(defaultOptions.gisId,pd.layerIds,pd.timesArr,time.getTime());
							}
						});
					
				}).on("click",".cafe-tl-play-icon",function(){						//点击播放
					if($(this).hasClass("active")){
						GLMap.getLayer('boundaryLayerId').visible=true;
						$(this).removeClass("active");
						$(this).find("i.cafe-ifont").remove();
						clearInterval($(this).val());
					}else{
						GLMap.getLayer('boundaryLayerId').visible=false;
						$(this).addClass("active");
						$(this).append($('<i>').addClass("cafe-ifont cafe-ic-zanting"));
						that.play($wrap,defaultOptions);
					}
				}).on("click",".cafe-tl-right-icon",function(){						//点击向右
					var $slider = $(".cafe-tl-sta-t-slider");
					var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
					var $tip = $wrap.find(".cafe-tl-sta-t-tip");
					var timeArr = that.getPlayDataTimeArr($wrap);
					var duration = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
					var timeInterval = that.getSmoothti(duration)[1];
					var step = bgW / (duration / timeInterval);
					var curLeft = parseFloat($slider.css("left")) + step;
					var index = Math.ceil(curLeft/step);
					if(curLeft >= bgW - 12){
						index = timeArr.length - 1;
						curLeft = bgW - 12;
					}
					$slider.css("left",curLeft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(curLeft + 12) + "px");
					var time = new Date(dateUtil.convertStringToDate7(timeArr[index],"yyyy-MM-dd hh:mm:ss"));
					$tip.css("left",(curLeft - 60) + "px").find("span").text(time.format("hh:mm"));
					
					var playData = $wrap.find(".cafe-tl-smooth").data("playData");
					$.each(playData,function(k,pd){
						if(!$.isEmptyObject(pd)){
							GIS.GridShow.animate(defaultOptions.gisId,pd.layerIds,pd.timesArr,time.getTime());
						}
					});
				}).on("click",".cafe-tl-close-icon",function(){						//关闭
					var playData = $(this).closest(".cafe-tl-smooth").data("playData");
					$.each(playData,function(k,pd){
						if(!$.isEmptyObject(pd)){
							GIS.GridShow.animate(defaultOptions.gisId,pd.layerIds,pd.timesArr,pd.timesArr[pd.timesArr.length-1]);
						}
					});
					defaultOptions.container.empty();
					defaultOptions.container.hide();
				//	GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
					if($.isFunction(defaultOptions.callback)){
						defaultOptions.callback();
					}
				})
				
			},
			//环境用
			bindEventHJ : function($wrap){
				var that = this;
				//单击弹出框的头部，确定点击处的位置
				$wrap.find(".cafe-tl-smooth").mousedown(function(event){
					var select = $wrap.find(".cafe-tl-sts-tselect");
					var slider = $wrap.find(".cafe-tl-sta-t-slider");
					var left = $wrap.find(".cafe-tl-left-icon");
					var player = $wrap.find(".cafe-tl-play-icon");
					var right = $wrap.find(".cafe-tl-right-icon");
					var close = $wrap.find(".cafe-tl-close-icon");
					
					if(!select.is(event.target) && !slider.is(event.target) && !left.is(event.target) && !player.is(event.target) && !right.is(event.target) && !close.is(event.target)){
						$(this).css({"cursor": "all-scroll"});						//点击鼠标切换图形
						event.stopPropagation();
						event.preventDefault();
						var isMove = true;
						var _this = defaultOptions.container;
				
						var m_x = Number(_this.css("left").split("px")[0]);//点击窗体时，left
						var m_y = Number(_this.css("top").split("px")[0]);//点击窗体时，top
						var abs_x = event.pageX;		//点击窗体时，左边距
						var abs_y = event.pageY;		//点击窗体时，上边距
						//单击住头部可进行拖拽，计算移动大小，以及移动范围限制
						$(document).unbind('mousemove').bind('mousemove',function(event){
							if(isMove) {
								//event.pageX,移动后的左边距;event.pageY,移动后的上边距
								var ebs_x = m_x-(abs_x-event.pageX); //移动后的left
								var ebs_y = m_y+(event.pageY - abs_y);//移动后的top
								
								var body_w =  $('.cafe-container').width();
								var body_h = $('.cafe-container').height();
								
								var div_w = _this.find(".cafe-tl-smooth").outerWidth();
								var div_h = _this.find(".cafe-tl-smooth").outerHeight();
								//不可超出左右边框
								if(ebs_x <= 0) {
									ebs_x = 0;
								} else if (ebs_x > body_w - div_w) {
									ebs_x = body_w - div_w;
								} 
								
								//不可超出上下边框
								if(ebs_y <= 0) {
									ebs_y = 0;
								} else if (ebs_y > body_h - div_h) {	//减去上下的蓝边高
									ebs_y = body_h - div_h;
								} 
								
								//重新设定弹出框的左边距，上边距
								_this.css({'left':ebs_x,'top':ebs_y });
							}
						}).mouseup(function(){
							isMove = false
							$(document).unbind('mousemove');
						});//鼠标移除事件；单击事件结束事件。
					}
				});
				
				
				$wrap.off().on("mousedown",".cafe-tl-sta-t-slider",function(event){	//拖动滑块
					var left = parseFloat($(this).css("left"));
					var that = this;
					var ti = $wrap.find(".cafe-tl-sts-tl-name").attr("tmid") * 60;
					var bgW =  $(this).siblings(".cafe-tl-sta-t-defbg").width();
					var per = ti / bgW;
					window.document.onmousemove = function(ev){
						ev.preventDefault();
						var step = 1;
						var $tip = $(that).siblings(".cafe-tl-sta-t-tip");
						var offset = ev.pageX-event.pageX;
						var _left = left + Math.round(offset / step) * step;
						if(_left <= -12){
							_left = -12;
						}else if(_left >= bgW - 12){
							_left = bgW - 12;
						}
						$(that).css("left",_left + "px").siblings(".cafe-tl-sta-t-bg").css("width",(_left + 12) + "px");
						var time = new Date($wrap.find(".cafe-tl-sta-timelabel").find("span:first").attr("time"));
						time.setMinutes(time.getMinutes() + Math.round((_left + 12) * per));
						$tip.css("left",(_left - 60) + "px").find("span").text(time.format("hh:mm"));
						
						GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,defaultOptions.times,time.getTime());
					};
					window.document.onmouseup = function(){
						window.document.onmousemove = null;
						window.document.onmouseup = null;
					};

				}).on("click",".cafe-tl-left-icon",function(){						//点击向左
						var $slider = $wrap.find(".cafe-tl-sta-t-slider");
						var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
						var $tip = $wrap.find(".cafe-tl-sta-t-tip");
						var timeArr = defaultOptions.times;
						var step = bgW / 3;
						var curLeft = parseFloat($slider.css("left")) - step;
						var index = Math.ceil(curLeft/step);
						if(curLeft <= -12){
							index = 0;
							curLeft = -12;
						}
						$slider.css("left",curLeft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(curLeft + 12) + "px");
						var time = new Date(timeArr[index]);
						$tip.css("left",(curLeft - 60) + "px").find("span").text(time.format("hh:mm"));
					
						GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,defaultOptions.times,time.getTime());
				}).on("click",".cafe-tl-play-icon",function(){						//点击播放
					if($(this).hasClass("active")){
						$(this).removeClass("active");
						$(this).find("i.cafe-ifont").remove();
						clearInterval($(this).val());
					}else{
						$(this).addClass("active");
						$(this).append($('<i>').addClass("cafe-ifont cafe-ic-zanting"));
						that.play2($wrap,defaultOptions);
					}
				}).on("click",".cafe-tl-right-icon",function(){						//点击向右
					var $slider = $wrap.find(".cafe-tl-sta-t-slider");
					var bgW =  $wrap.find(".cafe-tl-sta-t-defbg").width();
					var $tip = $wrap.find(".cafe-tl-sta-t-tip");
					var timeArr = defaultOptions.times;
					var step = bgW / 3;
					var curLeft = parseFloat($slider.css("left")) + step;
					var index = Math.ceil(curLeft/step);
					if(curLeft >= bgW - 12){
						index = timeArr.length - 1;
						curLeft = bgW - 12;
					}
					$slider.css("left",curLeft + "px").siblings(".cafe-tl-sta-t-bg").css("width",(curLeft + 12) + "px");
					var time = new Date(timeArr[index]);
					$tip.css("left",(curLeft - 60) + "px").find("span").text(time.format("hh:mm"));
					
					GIS.GridShow.animate(defaultOptions.gisId,defaultOptions.layerIds,defaultOptions.times,time.getTime());
				}).on("click",".cafe-tl-close-icon",function(){						//关闭
					defaultOptions.container.empty();
					defaultOptions.container.hide();
				//	GIS.LayerControll.deleteLayer(defaultOptions.gisId,defaultOptions.layerIds);
					if($.isFunction(defaultOptions.callback)){
						defaultOptions.callback();
					}
				})
				
			}
		}
		
		player._init();
		
		return player;
	}
	
});
